//
//  GuideDetailViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15/11/16.
//  Copyright © 2015年 RuiBen. All rights reserved.
//

#import "GuideDetailViewController.h"

@interface GuideDetailViewController ()
{
    NSMutableArray *guideDetailFeatureNameArray;
}
@end

@implementation GuideDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    guideDetailFeatureNameArray=[NSMutableArray array];
    [_guideDetailAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_guideDetailAlphaView addTarget:self action:@selector(guideDetailAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    [self requestGuideDetail:_guideCodeString];
}
-(void)requestGuideDetail:(NSString *)guideCodeStr
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:guideCodeStr forKey:@"GuideCode"];
        
        [HttpRequest requestData:@"ShopManager/GetGuideDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    _guideDetailPhoneLabel.text=[severDataDict.dataDict objectForKey:@"Phone"];
                    _guideDetailNameLabel.text=[severDataDict.dataDict objectForKey:@"GuideName"];
                    _guideDetailUserNameLabel.text=[severDataDict.dataDict objectForKey:@"LoginName"];
                    
                    _guideDetailStoreNameLabel.text=[severDataDict.dataDict objectForKey:@"StoreName"];
                    _guideDetailTimeLabel.text=[severDataDict.dataDict objectForKey:@"OnBoardDate"];
                    _guideDetailAddressLabel.text=[NSString stringWithFormat:@"%@%@%@%@",[severDataDict.dataDict objectForKey:@"ProvinceName" ],[severDataDict.dataDict objectForKey:@"CityName"],[severDataDict.dataDict objectForKey:@"RegionName"],[severDataDict.dataDict objectForKey:@"Address"]];
                    _guideDetailTextView.text=[severDataDict.dataDict objectForKey:@"Remark"];
                   
                    [guideDetailFeatureNameArray removeAllObjects];
                    NSMutableArray *dataArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (int i=0; i<dataArray.count; i++) {
                        
                        [guideDetailFeatureNameArray addObject:[[dataArray objectAtIndex:i] objectForKey:@"FeatureName"]];
                    }
                    for (UIButton *button in _guideDetailTagView.subviews) {
                        [button removeFromSuperview];
                        
                    }
                    
                    [self setGuideDetailTagView];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        [Global loginViewController:self noteStr:requestResultStr];
                        // [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
    
}

-(void)setGuideDetailTagView
{
    [_guideDetailTagView setTags:guideDetailFeatureNameArray];
}

-(void)guideDetailAlphaViewClick
{
    if (self.view!=nil) {
        [self.view removeFromSuperview];
        [self removeFromParentViewController];
        
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
